import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 徐海涛
 * Date: 2022-04-18
 * Time: 14:06
 */

//汽水瓶
public class Demo3 {
    public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();//n个空瓶子
            if(n == 0) {
                return;
            }
            int c = func(n);
            System.out.println(c);
        }

    }
    public static int func(int m) {
        int sum = 0;//记录喝的饮料
        // n = 1的时候,需要借两瓶,但是 无法还两瓶,所以排除
        // n = 2的时候,刚好借一瓶 喝了能 还 一瓶
        while (m > 2) {
            sum = sum + m/3;
            m = m/3 + m%3;
        }
        if(m == 2) {
            sum = sum +1;
        }
        return sum;
    }

}
